/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.router.core.service.receipt;


import cn.hutool.core.bean.BeanUtil;
import info.peigen.hotpot.business.router.core.repository.entity.RouterChannelEntity;
import info.peigen.hotpot.business.router.core.service.base.AbstractRouterQueryService;
import info.peigen.hotpot.business.router.facade.QueryReceiptChannelFacade;
import info.peigen.hotpot.business.router.facade.order.payee.QueryReceiptChannelOrder;
import info.peigen.hotpot.business.router.facade.result.receipt.QueryReceiptChannelResult;
import info.peigen.hotpot.business.router.facade.result.receipt.info.ReceiptChannelInfo;
import info.peigen.hotpot.common.service.base.ServiceQuery;
import info.peigen.hotpot.common.service.base.ServiceQueryContext;
import org.noear.solon.annotation.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <b>(ReceiptChannelService)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/8/31
 */
@SuppressWarnings("unchecked")
@Component
public class QueryReceiptChannelService extends AbstractRouterQueryService implements QueryReceiptChannelFacade {
    @Override
    public QueryReceiptChannelResult queryAllReceiptChannel(QueryReceiptChannelOrder order) {
        ServiceQueryContext serviceContext = new ServiceQueryContext().setOrder(order)
                .setResult(new QueryReceiptChannelResult());

        query(serviceContext, new ServiceQuery() {
            @Override
            public void query(ServiceQueryContext serviceContext) {
                List<RouterChannelEntity> entities = routerChannelRepository.getMapper().all();
                ((QueryReceiptChannelResult) serviceContext.getResult()).fromSuccess(entities.stream()
                        .map(entity -> BeanUtil.copyProperties(entity, ReceiptChannelInfo.class))
                        .collect(Collectors.toList()));
            }

            @Override
            public void convert(ServiceQueryContext serviceContext) {

            }
        });
        return (QueryReceiptChannelResult) serviceContext.getResult();
    }

}